<template>
<h1>员工列表练习</h1>
 <el-form style="width: 600px;margin:0 auto;" label-width="100px">
   <el-form-item label="姓名">
     <el-input placeholder="请输入员工姓名" v-model="user.name"></el-input>
   </el-form-item>
   <el-form-item label="工资">
     <el-input placeholder="请输入员工工资" v-model="user.say"></el-input>
   </el-form-item>
   <el-form-item label="职位">
     <el-input placeholder="请输入员工职位" v-model="user.job"></el-input>
   </el-form-item>
 </el-form>
  <el-button type="primary" @click="add">点击添加</el-button>

  <el-table :data="arr" style="width: 600px;margin: 0 auto;">
    <el-table-column type="index" label="编号" width:80px align="center"></el-table-column>
    <el-table-column prop="name" label="姓名"  align="center"></el-table-column>
    <el-table-column prop="say" label="工资"  align="center"></el-table-column>
    <el-table-column prop="job" label="职位"  align="center"></el-table-column>
    <el-table-column label="操作">
      <template #default="scope">
        <el-button type="danger" @click="del(scope.$index,scope.row)">删除</el-button>
      </template>
    </el-table-column>

  </el-table>


</template>


<script setup>

import {ref} from "vue";
import {ElMessage} from "element-plus";

const user = ref([
  {name:'',say:'',job:''}
])
const arr = ref([])
const add = () =>{
  if (user.value.name.trim()==''||user.value.say.trim()==''||user.value.job.trim()==''){
    ElMessage.error('请填写完整信息！')
    return;
  }
  arr.value.push(user.value);
  user.value= {name:'',say:'',job:''};
}
const del = (index,row) =>{
  if (confirm('您确定删除'+row.name+'吗')){
    arr.value.splice(index,1);
    ElMessage.success('删除成功！');
  }
}

</script>



<style scoped>

</style>